﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using GPCSC.IDAL;
using Maticsoft.DBUtility;//Please add references
namespace GPCSC.SQLServerDAL
{
	/// <summary>
	/// 数据访问类:newstable
	/// </summary>
	public partial class newstable:Inewstable
	{
		public newstable()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(Guid NewsID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from newstable");
			strSql.Append(" where NewsID=@NewsID ");
			SqlParameter[] parameters = {
					new SqlParameter("@NewsID", SqlDbType.UniqueIdentifier,16)};
			parameters[0].Value = NewsID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(GPCSC.Model.newstable model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into newstable(");
            strSql.Append("NewsID,NewsTitles,Newscontent,FBdate,BTSBLMID,BTSBLMName,IsImageNews,IsDel,NewsZZ,IsFsDx)");
			strSql.Append(" values (");
            strSql.Append("@NewsID,@NewsTitles,@Newscontent,@FBdate,@BTSBLMID,@BTSBLMName,@IsImageNews,@IsDel,@NewsZZ,@IsFsDx)");
			SqlParameter[] parameters = {
					new SqlParameter("@NewsID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@NewsTitles", SqlDbType.VarChar,100),
					new SqlParameter("@Newscontent", SqlDbType.NVarChar,160000),
					new SqlParameter("@FBdate", SqlDbType.VarChar,50),
					new SqlParameter("@BTSBLMID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@BTSBLMName", SqlDbType.VarChar,50),
					new SqlParameter("@IsImageNews", SqlDbType.Int,4),
					new SqlParameter("@IsDel", SqlDbType.Int,4),
                    new SqlParameter("@NewsZZ", SqlDbType.VarChar,50),
                    new SqlParameter("@IsFsDx", SqlDbType.Int,4)
                    };
            parameters[0].Value = model.NewsID;
			parameters[1].Value = model.NewsTitles;
			parameters[2].Value = model.Newscontent;
			parameters[3].Value = model.FBdate;
            parameters[4].Value = model.BTSBLMID;
			parameters[5].Value = model.BTSBLMName;
			parameters[6].Value = model.IsImageNews;
			parameters[7].Value = model.IsDel;
            parameters[8].Value = model.NewsZZ;
            parameters[9].Value = model.IsFsDx;
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(GPCSC.Model.newstable model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update newstable set ");
			strSql.Append("NewsTitles=@NewsTitles,");
			strSql.Append("Newscontent=@Newscontent,");
			strSql.Append("FBdate=@FBdate,");
			strSql.Append("BTSBLMID=@BTSBLMID,");
			strSql.Append("BTSBLMName=@BTSBLMName,");
			strSql.Append("IsImageNews=@IsImageNews,");
			strSql.Append("IsDel=@IsDel,");
            strSql.Append("NewsZZ=@NewsZZ,");
            strSql.Append("IsFsDx=@IsFsDx");
			strSql.Append(" where NewsID=@NewsID ");
			SqlParameter[] parameters = {
					new SqlParameter("@NewsTitles", SqlDbType.VarChar,100),
					new SqlParameter("@Newscontent", SqlDbType.NVarChar,160000),
					new SqlParameter("@FBdate", SqlDbType.VarChar,50),
					new SqlParameter("@BTSBLMID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@BTSBLMName", SqlDbType.VarChar,50),
					new SqlParameter("@IsImageNews", SqlDbType.Int,4),
					new SqlParameter("@IsDel", SqlDbType.Int,4),
					new SqlParameter("@NewsID", SqlDbType.UniqueIdentifier,16),
                    new SqlParameter("@NewsZZ", SqlDbType.VarChar,50) ,
                       new SqlParameter("@IsFsDx", SqlDbType.Int,4)
                                        };
			parameters[0].Value = model.NewsTitles;
			parameters[1].Value = model.Newscontent;
			parameters[2].Value = model.FBdate;
			parameters[3].Value = model.BTSBLMID;
			parameters[4].Value = model.BTSBLMName;
			parameters[5].Value = model.IsImageNews;
			parameters[6].Value = model.IsDel;
			parameters[7].Value = model.NewsID;
            parameters[8].Value = model.NewsZZ;
            parameters[9].Value = model.IsFsDx;
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(Guid NewsID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from newstable ");
			strSql.Append(" where NewsID=@NewsID ");
			SqlParameter[] parameters = {
					new SqlParameter("@NewsID", SqlDbType.UniqueIdentifier,16)};
			parameters[0].Value = NewsID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string NewsIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from newstable ");
			strSql.Append(" where NewsID in ("+NewsIDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public GPCSC.Model.newstable GetModel(Guid NewsID)
		{
			
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 NewsID,NewsTitles,Newscontent,FBdate,BTSBLMID,BTSBLMName,IsImageNews,IsDel,NewsZZ,IsFsDx from newstable ");
			strSql.Append(" where NewsID=@NewsID ");
			SqlParameter[] parameters = {
					new SqlParameter("@NewsID", SqlDbType.UniqueIdentifier,16)};
			parameters[0].Value = NewsID;

			GPCSC.Model.newstable model=new GPCSC.Model.newstable();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["NewsID"]!=null && ds.Tables[0].Rows[0]["NewsID"].ToString()!="")
				{
					model.NewsID= new Guid(ds.Tables[0].Rows[0]["NewsID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["NewsTitles"]!=null && ds.Tables[0].Rows[0]["NewsTitles"].ToString()!="")
				{
					model.NewsTitles=ds.Tables[0].Rows[0]["NewsTitles"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Newscontent"]!=null && ds.Tables[0].Rows[0]["Newscontent"].ToString()!="")
				{
					model.Newscontent=ds.Tables[0].Rows[0]["Newscontent"].ToString();
				}
				if(ds.Tables[0].Rows[0]["FBdate"]!=null && ds.Tables[0].Rows[0]["FBdate"].ToString()!="")
				{
					model.FBdate=ds.Tables[0].Rows[0]["FBdate"].ToString();
				}
				if(ds.Tables[0].Rows[0]["BTSBLMID"]!=null && ds.Tables[0].Rows[0]["BTSBLMID"].ToString()!="")
				{
					model.BTSBLMID= new Guid(ds.Tables[0].Rows[0]["BTSBLMID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["BTSBLMName"]!=null && ds.Tables[0].Rows[0]["BTSBLMName"].ToString()!="")
				{
					model.BTSBLMName=ds.Tables[0].Rows[0]["BTSBLMName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["IsImageNews"]!=null && ds.Tables[0].Rows[0]["IsImageNews"].ToString()!="")
				{
					model.IsImageNews=int.Parse(ds.Tables[0].Rows[0]["IsImageNews"].ToString());
				}
				if(ds.Tables[0].Rows[0]["IsDel"]!=null && ds.Tables[0].Rows[0]["IsDel"].ToString()!="")
				{
					model.IsDel=int.Parse(ds.Tables[0].Rows[0]["IsDel"].ToString());
				}
                if (ds.Tables[0].Rows[0]["NewsZZ"] != null && ds.Tables[0].Rows[0]["NewsZZ"].ToString() != "")
                {
                    model.NewsZZ = ds.Tables[0].Rows[0]["NewsZZ"].ToString();
                }
                if (ds.Tables[0].Rows[0]["IsFsDx"] != null && ds.Tables[0].Rows[0]["IsFsDx"].ToString() != "")
                {
                    model.IsFsDx = int.Parse(ds.Tables[0].Rows[0]["IsFsDx"].ToString());
                }
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select NewsID,NewsTitles,Newscontent,FBdate,BTSBLMID,BTSBLMName,IsImageNews,IsDel,NewsZZ ,IsFsDx");
			strSql.Append(" FROM newstable ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
            strSql.Append(" NewsID,NewsTitles,Newscontent,FBdate,BTSBLMID,BTSBLMName,IsImageNews,IsDel,NewsZZ ,IsFsDx");
			strSql.Append(" FROM newstable ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "newstable";
			parameters[1].Value = "NewsID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

